package AppleCakeMining;
import java.util.ArrayList;
import java.util.Collections;


public class GlobalTransactionList {
	private ArrayList<Transaction> transactions;
	private static GlobalTransactionList instance;
	
	private GlobalTransactionList() {
		transactions = new ArrayList<Transaction>();
	}
	
	public static GlobalTransactionList getInstance() {
		if(instance == null) {
			instance = new GlobalTransactionList();
		}
		return instance;
	}

	/*public void addTransaction(String read) {
		Transaction newTrans = new Transaction();
		transactions.add(newTrans);
		String[] ids = read.split(" ");
		int previousId = -1;
		for(String id:ids) {
			Integer castId = Integer.valueOf(id); 
			if(castId != previousId) {
				gil.addItem(castId);
				newTrans.addItem(castId);
				previousId = castId;
			}
		}
	}*/
	
	public void addTransaction(Transaction t) {
		transactions.add(t);
	}
	
	public int getTotalTransactions() {
		return transactions.size();
	}

	public void printAllTransactions() {
		for(Transaction t:transactions) {
			t.printAllItems();
		}
	}

	public int calculateSupport(ArrayList<Item> items) {
		int support = 0;
		for(Transaction t:transactions) {
			if(t.containsAll(items)) {
				support++;
			}
		}
		return support;
		
	}

	@SuppressWarnings("unchecked")
	public ArrayList<Transaction> getTransactions() {
		Collections.sort(transactions);
		return transactions;
	}

	public void clear() {
		transactions = new ArrayList<Transaction>();
	}

	
}
